package shop.services.manage.dictionary.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import shop.core.ServicesManager;
import shop.services.manage.dictionary.DictionarySerivice;
import shop.services.manage.dictionary.bean.Dictionary;
import shop.services.manage.dictionary.dao.DictionaryDao;

import javax.annotation.Resource;

/**
 * 字典管理接口实现
 **/
@Service
public class DictionaryServiceImpl extends ServicesManager<Dictionary, DictionaryDao> implements DictionarySerivice {

    @Resource(name = "dictionaryDaoManage")
    @Override
    public void setDao(DictionaryDao dictionaryDao) {
        this.dao = dictionaryDao;
    }
    //重写接口改变状态方法
    @Override
    public void updateDictionaryStatus(String[] ids, String status, String updateDictionary) {
        if (ids == null || ids.length == 0) {
            throw new NullPointerException("ID不能为空！");
        }
        if (StringUtils.isBlank(updateDictionary)) {
            throw new NullPointerException("操作人账号不能为空！");
        }
        for (int i = 0; i < ids.length; i++) {
            if (StringUtils.isBlank(ids[i])) {
                throw new NullPointerException("ID不能存在空的！");
            }
            Dictionary d = new Dictionary();
            d.setId(ids[i]);
            d.setStatus(status);
            dao.updateDictionaryStatus(d);
        }
    }
}
